﻿@page
@model IndexModel
@{
    ViewBag.Title = "应用程序列表";
    ViewBag.Current = "open.apps";
}

<div class="card data-list">
    <div class="toolbar card-header">
        <form method="get">
            <div>
                <gt:enum-dropdownlist asp-for="Query.Status" default-text="请选择状态"></gt:enum-dropdownlist>
            </div>
            <div>
                <input class="form-control" placeholder="应用程序Id" asp-for="Query.AppId" />
            </div>
            <div class="input-group-append">
                <input class="form-control" placeholder="应用名称" asp-for="Query.Name" />
                <button type="submit"><i class="bi-search"></i></button>
            </div>
        </form>
        <div class="actions">
            <gt:action-group>
                <gt:action .permission="@Permissions.Create" typeof="Add" asp-page="./Edit">添加应用</gt:action>
                <gt:action .permission="@Permissions.Delete" typeof="Delete" confirm="你确定要删除所选择的应用吗？" asp-page-handler="Delete"></gt:action>
            </gt:action-group>
        </div>
    </div>

    <div class="card-body">
        <table class="table table-hover" .warning="Model.Items" .warning-text="还没有找到任何应用程序！">
            <thead>
                <tr>
                    <th class="checkbox"><gt:checkall /></th>
                    <th>应用名称</th>
                    <th>所属用户</th>
                    <th>添加时间/过期时间</th>
                    <th class="text-center">操作</th>
                </tr>
            </thead>
            <tbody class="align-middle">
                @foreach (var app in Model.Items)
                {
                    <tr class="data-item">
                        <td class="checkbox"><gt:checkbox value="@app.Id"></gt:checkbox></td>
                        <td>
                            <div class="mb-2">
                                <span .class-alert-success="@(app.Status == ApplicationStatus.Normal)" .class-alert-danger="@(app.Status != ApplicationStatus.Normal)" class="label alert">@Model.Localizer.GetString(app.Status)</span>
                                <b>@app.Name</b>
                            </div>
                            <small><i>AppId：</i><span title="点击进行拷贝" _click="copy" class="alert alert-info text-uppercase">@app.Id</span></small>
                            <small><i>AppSecret：</i><span title="点击进行拷贝" _click="copy" class="alert alert-info text-uppercase">@app.AppSecret</span></small>
                            <div class="text-muted">@Html.Raw(app.Summary)</div>
                        </td>
                        <td>@(app["NickName"])</td>
                        <td>添加：@app.CreatedDate.ToString("yyyy-MM-dd")<br />过期：@app.ExpiredDate.ToString("yyyy-MM-dd")</td>
                        <td>
                            <gt:action-dropdownmenu>
                                <gt:action typeof="Edit" .permission="@Permissions.Update" asp-page="./Edit" asp-route-id="@app.Id"></gt:action>
                                <gt:action typeof="Delete" .permission="@Permissions.Delete" confirm="你确定要删除“@app.Name”吗？" asp-page-handler="Delete" asp-route-id="@app.Id"></gt:action>
                                <gt:action typeof="Divider"></gt:action>
                                <gt:action typeof="Link" .permission="@Permissions.Setting" title="API列表" asp-page="./Apis" asp-route-appid="@app.Id"><i class="bi-list"></i> API列表</gt:action>
                            </gt:action-dropdownmenu>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
        <gt:page asp-route-userid="@Model.Query.UserId" asp-route-status="@Model.Query.Status" asp-route-user-name="@Model.Query.UserName" asp-route-appid="@Model.Query.AppId" asp-route-name="@Model.Query.Name" data="Model.Items"></gt:page>
    </div>
</div>
